// test_cors.js - 测试CORS配置
const axios = require('axios');

async function testCORS() {
    try {
        console.log("测试CORS配置...");
        
        // 模拟前端请求
        const response = await axios.post('http://localhost:3000/api/users/login', {
            email: 'test@example.com',
            password: 'password123'
        }, {
            headers: {
                'Origin': 'http://127.0.0.1:5174',
                'Content-Type': 'application/json'
            }
        });
        
        console.log("请求成功:", response.status);
        console.log("响应头:", response.headers);
        
    } catch (error) {
        if (error.response) {
            console.log("响应状态:", error.response.status);
            console.log("响应头:", error.response.headers);
            console.log("响应数据:", error.response.data);
        } else {
            console.error("请求失败:", error.message);
        }
    }
}

testCORS();